﻿using Finbook.GameApp.Models;
using Finbook.GameApp.Models.V3;
using Finbook.GameApp.Models.V4;
using Finbook.GameApp.Models.V5;
using Finbook.GameApp.Models.V6;
using System;
using System.Linq;

namespace Finbook.GameApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //GameV1Start();
                //GameV2Start();
                //GameV3Start();
                //Game4Start();
                //Game5Start();
                Game6Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }

        private static void Game6Start()
        {
            var player = new PlayerV6(300, "中自治"); 
             var monster = new MonsterV6(400, "美联邦");
            player.Skills.Add(SkillV6.CreateSkill(15, SkillType.Damage, SkillTarget.Enemy));
            player.Skills.Add(SkillV6.CreateSkill(10, SkillType.Heal));
            player.Skills.Add(SkillV6.CreateSkill(15, SkillType.Damage, SkillTarget.Self));
            monster.Skills.Add(SkillV6.CreateSkill(15, SkillType.Damage, SkillTarget.Enemy));
            monster.Skills.Add(SkillV6.CreateSkill(10, SkillType.Heal));
            monster.Skills.Add(SkillV6.CreateSkill(15, SkillType.Damage, SkillTarget.Self));

            CommonConsole.WriteLine("//******游戏开始", ConsoleColor.Red);
            while (true)
            {
                if (GameAct(player, monster))
                {
                    break;
                }
                if (GameAct(monster, player))
                {
                    break;
                }
            }
            if (player.HP < 0)
            {
                CommonConsole.WriteLine($"{player.Name}胜利", ConsoleColor.Red);
            }
            else
            {
                CommonConsole.WriteLine($"{monster.Name}胜利", ConsoleColor.Red);
            }
        }

        private static bool GameAct(RoleV6 player, RoleV6 monster)
        {
            var skill = player.SelectSkill();
            monster.BeHit(skill, player);
            return monster.HP <= 0;

        }

        private static void Game5Start()
        {
            var player = new PlayerV5(300);
            var monster = new MonsterV5(400);
            player.Skills.Add(SkillV5.CreateSkill(15, SkillType.Damage));
            player.Skills.Add(SkillV5.CreateSkill(10, SkillType.Heal));
            monster.Skills.Add(SkillV5.CreateSkill(15, SkillType.Damage));
            monster.Skills.Add(SkillV5.CreateSkill(12, SkillType.Damage));

            CommonConsole.WriteLine("//******游戏开始", ConsoleColor.Red);
            while (true)
            {
                var skill = player.SelectSkill();
                var role = player.GetSkillTarget(skill.SkillType, monster);
                role.BeHit(skill);
                if (monster.HP <= 0)
                {
                    break;
                }

                skill = monster.SelectSkill();
                role = monster.GetSkillTarget(skill.SkillType, player);
                role.BeHit(skill);
                if (player.HP <= 0)
                {
                    break;
                }
            }
            if (player.HP < 0)
            {
                CommonConsole.WriteLine("怪兽胜利", ConsoleColor.Red);
            }
            else
            {
                CommonConsole.WriteLine("玩家胜利", ConsoleColor.Red);
            }
        }

        private static void Game4Start()
        {
            var player = new PlayerV4(300);
            var monster = new MonsterV4(400);
            for (int i = 0; i < 10; i++)
            {
                player.Skills.Add(new Skill(10 + i));
                monster.Skills.Add(new Skill(10 + i));
            }
            CommonConsole.WriteLine("//******游戏开始", ConsoleColor.Red);
            while (true)
            {
                var skill = player.SelectSkill();
                monster.BeHit(skill.SkillDamage);
                CommonConsole.WriteLine($"怪物被攻击，受到伤害：{skill.SkillDamage},当前血量：{monster.HP}", ConsoleColor.Blue);
                if (monster.HP <= 0)
                {
                    break;
                }

                skill = monster.SelectSkill();
                player.BeHit(skill.SkillDamage);
                CommonConsole.WriteLine($"玩家被攻击，受到伤害：{skill.SkillDamage},当前血量：{player.HP}", ConsoleColor.Green);
                if (player.HP <= 0)
                {
                    break;
                }
            }
            if (player.HP < 0)
            {
                CommonConsole.WriteLine("怪兽胜利", ConsoleColor.Red);
            }
            else
            {
                CommonConsole.WriteLine("玩家胜利", ConsoleColor.Red);
            }
        }

        private static void GameV3Start()
        {
            var player = new Player(300);
            var monster = new Monster(300);
            for (int i = 1; i <= 5; i++)
            {
                player.Skills.Add(new Skill(i));
                monster.Skills.Add(new Skill(i));
            }
            Console.WriteLine("游戏开始");
            while (true)
            {
                var skill = player.SelectSkill();
                monster.BeHit(skill.SkillDamage);
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine($"怪兽被攻击，受到伤害：{skill.SkillDamage},当前血量：{monster.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (monster.HP <= 0)
                {
                    break;
                }

                skill = monster.SelectSkill();
                player.BeHit(skill.SkillDamage);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine($"玩家被攻击，受到伤害：{skill.SkillDamage},当前血量：{player.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (player.HP <= 0)
                {
                    break;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            if (player.HP <= 0)
            {
                Console.WriteLine("怪兽胜利！");
            }
            else
            {
                Console.WriteLine("玩家胜利！");
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("游戏结束");
        }

        private static void GameV2Start()
        {
            var player = new RoleV2(300);
            var monster = new RoleV2(300);
            for (int i = 0; i < 5; i++)
            {
                player.Skills.Add(new Skill(i));
                monster.Skills.Add(new Skill(i));
            }
            Console.WriteLine("游戏开始");
            while (true)
            {
                var playSkill = player.Skills.ElementAt(new Random().Next(0, player.Skills.Count));
                monster.BeHit(playSkill);
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine($"怪兽被攻击，收到伤害：{playSkill.SkillDamage},当前血量：{monster.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (monster.HP <= 0)
                {
                    break;
                }

                var monsterSkill = monster.Skills.ElementAt(new Random().Next(0, monster.Skills.Count));
                player.BeHit(monsterSkill);
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine($"怪兽被攻击，收到伤害：{monsterSkill.SkillDamage},当前血量：{player.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (player.HP <= 0)
                {
                    break;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            if (player.HP <= 0)
            {
                Console.WriteLine("怪兽胜利！");
            }
            else
            {
                Console.WriteLine("玩家胜利！");
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("游戏结束");
        }

        private static void GameV1Start()
        {
            var player = new Role(300, 20);
            var monster = new Role(500, 10);
            Console.WriteLine("游戏开始");
            while (true)
            {
                monster.BeHit(player.Damage);
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine($"怪兽被攻击，收到伤害：{player.Damage},当前血量：{monster.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (monster.HP <= 0)
                {
                    break;
                }

                player.BeHit(monster.Damage);
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine($"怪兽被攻击，收到伤害：{monster.Damage},当前血量：{player.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (player.HP <= 0)
                {
                    break;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            if (player.HP <= 0)
            {
                Console.WriteLine("怪兽胜利！");
            }
            else
            {
                Console.WriteLine("玩家胜利！");
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("游戏结束");
        }
    }
}
